#!/usr/bin/env bash
ENV=$1
APP_NAME=$2
BASE_DIR=/data/config
APP_DIR=$BASE_DIR/$APP_NAME
REGISTRY_URL=swr.cn-east-3.myhuaweicloud.com/access/
TAG="$ENV."`date '+%Y%m%d%H%M%S'`
IMAGE="$REGISTRY_URL$APP_NAME:$TAG"

curl -o Dockerfile http://deploy-dev.idanchuang.vpc/app/getAppDockerFile/$APP_NAME/$ENV
sleep 1

echo "APP_DIR=$APP_DIR"
echo "IMAGE=$IMAGE"

{
	docker build -t $IMAGE . \
	&& docker push $IMAGE \
	&& docker rmi $IMAGE
} || {
    echo "镜像制作异常,请联系运维人员解决"
    exit 1
}